<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*,com.hz.framework.util.*" %>
<%@ include file="../common/commonJS.jsp" %>
<%@ include file="../common/commonLabel.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String year = request.getAttribute("funddate")==null?(String)request.getAttribute("year"):((String)request.getAttribute("funddate")).split("-")[0];
String month = request.getAttribute("funddate")==null?(String)request.getAttribute("month"):((String)request.getAttribute("funddate")).split("-")[1];
String[] tpflag = (String[])request.getAttribute("tpflag");//数据信息
int row = Integer.parseInt((String)request.getAttribute("row"));
%>

<HTML>
<HEAD>
<TITLE>财务收入支出表</TITLE>
<META content="text/html;charset=UTF-8" http-equiv=Content-Type>
<style type="text/css">
/* 操作列的宽度 */
.boxtd{
	width: 18%;
}
</style>
<script type="text/javascript">
function doRowsum(){
	var days = <%=tpflag.length %>;
	var dsum = 0;
	for(var j=0;j<days;j++){
		var day = document.all["tpflag"+j];
		var dasum = 0;
		if(day.length){
			for(var i =0;i<day.length;i++){
				dasum += (day[i].value-0);
			}
		}else{
			dasum += (day.value-0);
		}
		document.getElementById("sumtpflag"+j).innerHTML = dasum;
		dsum += dasum;
	}
	document.getElementById("fundsum").innerHTML = dsum;
}
function DoSel(y,m,d){
	if(m==""){
		document.all["year"].value = y;
		document.all["month"].value = d;
		document.forms[0].submit();
	}
}
function doPrint(){
	var oldaction = document.forms[0].action;
	document.forms[0].action = "<%=path %>/docs/ys_statistics/financial_statprint.jsp";
	document.forms[0].submit();
	document.forms[0].action = oldaction;
}
</script>
</HEAD>
<BODY onload="doRowsum()">
<form action="<%=path %>/financialstat.action" method="post" name="myform">
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
  <tr>
     <td>
     <table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" class="MainBody">
      <tr>
        <td width="760" class="MainBody_title"><hello:forValue type="title" /></td>
        <td></td>
      </tr>
        <tr>
			<td colspan="2" >
			<table border="0" width="100%" cellpadding="0" cellspacing="0" style="margin: 10 50 10 0;">
          		<tr>
	          	<td align="right" width="50%">
      			请选择：<select name="year" >
      			<% for (int i = Integer.parseInt(DateUtil.getYear()); i >Integer.parseInt(DateUtil.getYear())-7; i--) { 
      						%>
      					<option value="<%=i %>" <%=String.valueOf(i).equals(year)?"selected":"" %>><%=i %>年</option>
      				<%} %>
      		    </select>&nbsp;&nbsp;
      		    <select name="month" >
      		    	<option value="">请选择</option>
      				<% for (int i = 1; i <13; i++) {  %>
      					<option value="-<%=i<10?"0"+i:i %>" <%=String.valueOf(i<10?"-0"+i:"-"+i).equals(month)?"selected":"" %>><%=i %>月</option>
      				<%} %>
      		    </select>&nbsp;&nbsp;
		    	</td>
				<td align="left" >&nbsp;&nbsp;
					<input type="submit" class="btn" value="查询信息">
					&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="导出" class="btn" onclick="doPrint()"/>
				</td>
				<td width="30%">&nbsp;&nbsp;
					<input type="hidden" name="operate" value="sel">
					<input type="hidden" name="row" value="<%=row %>">
				</td>
				</tr>
			</table>
		<%
		List info = (List)request.getAttribute("listinfo");//数据信息
		%>
		<%-- 列表信息 全局 --%>
		<table border="1"  cellpadding="0" cellspacing="0" bordercolor="#B5DFF8" class="MainBody_table">
			<tr align="center">
				<th width="9%">日期</th>
				<th >订单预收</th>
				<th >订单结算</th>
				<th >其他收入</th>
				<th >采购支出</th>
				<th >其他支出</th>
				<th width="9%">金额合计</th>
			</tr>
		<%if(info!=null){ 
			 for(int j=1;j<=row;j++){
		%>
			<tr align="center" onmouseover="this.style.backgroundColor='#EEF7FD';" onmouseout="this.style.backgroundColor='';">
		        <th onclick="DoSel('<%=year %>','<%=month %>','<%=j<10?"-0"+j:"-"+j %>')"><%=year+month+(j<10?"-0"+j:"-"+j) %></th>
		        <%
		        double sum = 0;
		        for(int f=0;f<tpflag.length;f++){
					double one =0;
			        for(int i=0;i<info.size();i++){
						Map minfo = (Map)info.get(i);
						if((year+month+(j<10?"-0"+j:"-"+j)).equals(minfo.get("tpdate"))){
							one = minfo.get(tpflag[f]+"sum")==null?0:Double.parseDouble((String)minfo.get(tpflag[f]+"sum"));
							if(f>2){
								one = 0-one;
							}
							sum += one;
						}
			        }
		        %>
		        <td ><font color="<%=f>2?"red":"green"%>" style="font-weight: bold"><%=one%><input type="hidden" name="tpflag<%=f%>" value="<%=one%>"></td>
		        <%	
		        }  %>
		        <td ><%=CommonUtils.formatDouble(3,sum) %></td>
		   	</tr>
		   
		<% 	} %>
			<tr align="center" onmouseover="this.style.backgroundColor='#EEF7FD';" onmouseout="this.style.backgroundColor='';">
				<th >总合计：</th>
		        <%
		        for(int i=0;i<tpflag.length;i++){
		        %>
		        <td id="<%="sumtpflag"+i %>"></td>
		        <%} %>
		        <td id="fundsum"></td>
		   	</tr>
		<% }%>
		<c:if test="${empty listinfo}">
			<tr>
				<td colspan="7" align="center">暂时没有您可以浏览的信息 </td>
			</tr>
		</c:if>
		<c:if test="${!empty listinfo}">
			<tr>
				<td colspan="7" align="center" style="display: none;"><hello:AllPage /></td>
			</tr>
		</c:if>
		</table>
		</td>
    </tr>
   </table>
    </td>
  </tr>
 </table>
</form>
</BODY>
</HTML>
